/*
	StargateWW for GarrysMod10
	Copyright (C) 2008 Prefanatic

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

local meta = FindMetaTable( "Player" )

function meta:ShowKilledView( killer, teamkilled )

	umsg.Start("_KillView", self)
		umsg.Entity( killer )
		umsg.Bool( teamkilled )
	umsg.End()
	
end

function meta:SendSound( sound )

	umsg.Start("_Sound", self)
		umsg.String(sound)
	umsg.End()
	
end

function meta:DebugPrint( msg )
	--umsg.Start("_DebugPrint", self )
	--	umsg.String(msg)
	--umsg.End()
	
	self:PrintMessage(HUD_PRINTCONSOLE, msg)
end

function meta:CheckContentPack()
	umsg.Start("_CheckContent", self)
	umsg.End()
end

function SetHasPack( ply, haspack )

	ply:SetNWBool("hascontentpack", haspack)

end

function meta:PrintPack()

	umsg.Start("_PrintPack", self)
	umsg.End()
	
end

function Ping( ply )
		umsg.Start( "_Ping", ply )
			umsg.Long( os.time() )
		umsg.End()
end
concommand.Add( "PingServer", Ping )

function GetTeamName( base )

	for k,v in pairs(WWClass) do
	
		if base == v.TeamBase then class = v.TeamName break end
		
	end
	
	return class
	
end

--################# Wraith Feeding @Prefanatic
function WraithFeedingVictim(pl)
	pl:ConCommand("pp_motionblur 0")
	pl:ConCommand("pp_dof 0")
	pl:ConCommand("pp_colormod 0")
	pl:ConCommand("pp_sharpen 0" )
	pl:ConCommand("pp_mat_overlay 0")
	pl:ConCommand("pp_bloom 0")
	
	pl:ConCommand("pp_sharpen 1")
	pl:ConCommand("pp_sharpen_contrast 2")
	pl:ConCommand("pp_sharpen_distance 1")
	
	pl:ConCommand("pp_dof 1")
	pl:ConCommand("pp_dof_initlength 99")
	pl:ConCommand("pp_dof_spacing 60.22")
	
	pl:ConCommand("pp_colormod 1")
	pl:ConCommand("pp_colormod_addb 226")
	pl:ConCommand("pp_colormod_addr 226")
	pl:ConCommand("pp_colormod_addg 226")
    pl:ConCommand("pp_colormod_mulb 198")
	pl:ConCommand("pp_colormod_mulr 198")
	pl:ConCommand("pp_colormod_mulg 198")
	pl:ConCommand("pp_colormod_color 0")
	pl:ConCommand("pp_colormod_contrast 0.09")
	pl:ConCommand("pp_colormod_brightness 0")
	pl:ConCommand("pp_mat_overlay_refractamount 0.01")
	pl:ConCommand("pp_mat_overlay_texture models/shadertest/shader4")
	pl:ConCommand("pp_mat_overlay 1")
end

function WraithFeedingOwner(pl)
	pl:ConCommand("pp_motionblur 0")
	pl:ConCommand("pp_dof 0")
	pl:ConCommand("pp_colormod 0")
	pl:ConCommand("pp_sharpen 0" )
	pl:ConCommand("pp_mat_overlay 0")
	pl:ConCommand("pp_bloom 0")
	
	pl:ConCommand("pp_sharpen 1")
	pl:ConCommand("pp_sharpen_contrast 2")
	pl:ConCommand("pp_sharpen_distance 1")
	
	pl:ConCommand("pp_colormod 1")
	pl:ConCommand("pp_colormod_addb 68")
	pl:ConCommand("pp_colormod_addr 68")
	pl:ConCommand("pp_colormod_addg 68")
    pl:ConCommand("pp_colormod_mulb 0")
	pl:ConCommand("pp_colormod_mulr 150")
	pl:ConCommand("pp_colormod_mulg 22")
	pl:ConCommand("pp_colormod_color 0")
	pl:ConCommand("pp_colormod_contrast 0.65")
	pl:ConCommand("pp_colormod_brightness -0.95")
end

--################# Death effects @Prefanatic
function DeathScreen(pl)

	pl:ConCommand("pp_motionblur 0")
	pl:ConCommand("pp_dof 0")
	pl:ConCommand("pp_colormod 0")
	pl:ConCommand("pp_sharpen 0" )
	pl:ConCommand("pp_mat_overlay 0")
	pl:ConCommand("pp_bloom 0")
	
	pl:ConCommand("pp_motionblur 1")
	pl:ConCommand("pp_motionblur_addalpha 0.05")
	pl:ConCommand("pp_motionblur_delay 0.035")
	pl:ConCommand("pp_motionblur_drawalpha 1.00")
	pl:ConCommand("pp_dof 1")
	pl:ConCommand("pp_dof_initlength 10")
	pl:ConCommand("pp_dof_spacing 225")
	
	pl:ConCommand("pp_colormod 1")
	pl:ConCommand("pp_colormod_addb 40")
	pl:ConCommand("pp_colormod_addr 40")
	pl:ConCommand("pp_colormod_addg 40")
    pl:ConCommand("pp_colormod_mulb 22")
	pl:ConCommand("pp_colormod_mulr 150")
	pl:ConCommand("pp_colormod_mulg 0")
	pl:ConCommand("pp_colormod_color 0")
	pl:ConCommand("pp_colormod_contrast 0.56")
	pl:ConCommand("pp_colormod_brightness 0.24")
	pl:ConCommand("pp_mat_overlay_refractamount 0.007")
	pl:ConCommand("pp_mat_overlay_texture models/props_c17/frostedglass_01a")
	pl:ConCommand("pp_mat_overlay 1")



	pl:ConCommand("pp_sharpen 1" )
end

--################# Remove the death effects @Prefanatic
function RemoveDeathScreen(pl)
	pl:ConCommand("pp_motionblur 0")
	pl:ConCommand("pp_dof 0")
	pl:ConCommand("pp_colormod 0")
	pl:ConCommand("pp_sharpen 0" )
	pl:ConCommand("pp_mat_overlay 0")
	pl:ConCommand("pp_bloom 0")
end

--################# Reload fonts on the player client @Prefanatic
function ReloadF(ply)	
	umsg.Start("_Reload", ply)

	umsg.End()
end

--################# Notify selected players @Prefanatic
function Notify(ply, msg, time, death)	
deatha = death or false
	umsg.Start("_Notify", ply)
		umsg.String(msg)
		umsg.Short(time)
		umsg.Bool(deatha)
	umsg.End()
end

--################# Notify everyone @Prefanatic
function NotifyAll(msg, time, death)
	for k, v in pairs(player.GetAll()) do
		Notify(v, msg, time, death)
	end
end

--################# Print a message to everyone @Prefanatic
function PrintMessageAll(msg)
	for k, v in pairs(player.GetAll()) do
		v:PrintMessage(HUD_PRINTTALK, msg)
	end
end

--################# Talk to team @Prefanatic
function TalkToTeam(p, msg)
	if p:Team() >= 10 and p:Team() < 19 then
		for k, v in pairs(player.GetAll()) do
			if v:Team() >= 10 and v:Team() < 19 then
				if !p:Alive() then
					v:ChatPrint(p:Nick() .. " (DEAD): " .. msg )
				else
					v:ChatPrint(p:Nick() .. " (ATLANTIS): " .. msg )
				end
			end
		end
	end
	
	if p:Team() >= 20 and p:Team() < 29 then
		for k, v in pairs(player.GetAll()) do
			if v:Team() >= 20 and v:Team() < 29 then
				if !p:Alive() then
					v:ChatPrint(p:Nick() .. " (DEAD): " .. msg )
				else
					v:ChatPrint(p:Nick() .. " (WRAITH): " .. msg )
				end
			end
		end
	end
end

function AddDir(dir) // recursively adds everything in a directory to be downloaded by client
	local list = file.FindDir("../"..dir.."/*")
	for _, fdir in pairs(list) do
		if fdir != ".svn" then // don't spam people with useless .svn folders
			AddDir(fdir)
		end
	end
  
	for k,v in pairs(file.Find("../"..dir.."/*")) do
		resource.AddFile(dir.."/"..v)
	end
end 